﻿using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace Util
{
   public class Print
    {
        /// <summary>
        /// 扫描所有打印机
        /// </summary>
        /// <returns></returns>
        public static List<String> PrintMedias()
        {

            string query = string.Format("SELECT * from Win32_Printer");
            var searcher = new ManagementObjectSearcher(query);
            var printers = searcher.Get();


            List<String> list = new List<string>();

            foreach (var printer in printers)
            {
                var mediaName = printer.Properties["Name"].Value.ToString();
                if (printer.Properties["WorkOffline"].Value.Equals(true))
                {
                    mediaName += " (脱机) ";
                }

                list.Add(mediaName);
                //显示部分属性
                Console.WriteLine(printer.Properties["Name"].Value);                    //获取打印机名称
                Console.WriteLine(printer.Properties["PortName"].Value);                //获取打印机端口号
                Console.WriteLine(printer.Properties["Default"].Value);                 //获取打印机是否是默认打印机
                Console.WriteLine(printer.Properties["PrinterStatus"].Value);           //获取打印机工作状态
                Console.WriteLine();             //获取打印机是否离线

                //显示所有属性到即时窗口
                //foreach (var property in printer.Properties)
                //{
                //    Console.WriteLine(string.Format("\t{0}: {1}", property.Name, property.Value));
                //}

                Console.WriteLine();
            }

            return list;
        }


        public static void pr()
        {

        }
    }
}
